package com.google.code.constant;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import com.google.code.util.RTE;

public class T {
	public static final long _1SinMS = 1000;
	public static final long _1MinMS = 60 * _1SinMS;
	public static final long _1HinMS = 60 * _1MinMS;
	public static final long _1DayMS = 24 * _1HinMS;

	public static long TS() {
		return Calendar.getInstance().getTimeInMillis();
	}

	public static String TIME() {
		return TIME("yyyy-MM-dd hh:mm:ss");
	}

	public static String TIME(String format) {
		Format formatter;
		formatter = new SimpleDateFormat(format);
		return formatter.format(Calendar.getInstance().getTime());
	}

	public static long TS_OF_HOUR_OF_TODAY(int hour) {
		if (hour > 23 || hour < 0)
			return RTE.LONG();

		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.HOUR_OF_DAY, hour);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);

		return cal.getTimeInMillis();
	}

	public static int DAY_OF_TS(long ts) {
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(ts);
		return cal.get(Calendar.DATE);
	}

	public static int DAY_OF_NOW() {
		return Calendar.getInstance().get(Calendar.DATE);
	}

	public static int HOUR_OF_NOW() {
		return Calendar.getInstance().get(Calendar.HOUR);
	}

	public static boolean DUE_H(long ts1, int hour) {
		return T.DAY_OF_TS(ts1) < T.DAY_OF_TS(T.TS())
				&& T.HOUR_OF_NOW() >= hour;
	}

	public static boolean DUE(long ts) {
		return T.TS() >= ts;
	}

}
